home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / mint / mgr / sparcmgr / src.zoo / src / do_button.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-03-17  |  8.4 KB  |  302 lines

  1. /*                        Copyright (c) 1987 Bellcore
  2.  *                            All Rights Reserved
  3.  *       Permission is granted to copy or use this program, EXCEPT that it
  4.  *       may not be sold for profit, the copyright notice must be reproduced
  5.  *       on copies, and credit should be given to Bellcore where it is due.
  6.  *       BELLCORE MAKES NO WARRANTY AND ACCEPTS NO LIABILITY FOR THIS PROGRAM.
  7.  */
  8. /*    $Header: do_button.c,v 1.2 89/03/17 08:45:13 sau Exp $
  9.     $Source: /m1/mgr.new/src/RCS/do_button.c,v $
  10. */
  11. static char    RCSid_[] = "$Source: /m1/mgr.new/src/RCS/do_button.c,v $$Revision: 1.2 $";
  12.  
  13. /* Figure out what to do with a button push */
  14.  
  15. #include "bitmap.h"
  16. #include <stdio.h>     /* temporary */
  17. #include <sys/signal.h>
  18. #include "menu.h"
  19. #include "defs.h"
  20. #include "font.h"
  21. #include "event.h"
  22.  
  23. do_button(button)
  24. int button;
  25.    {
  26.    register WINDOW *win;        /* window of interest */
  27.    int choice;                /* current menu choice */
  28.    int choice_ok;            /* valid choice flag */
  29.    struct menu_state *state;        /* place to keep menu state */
  30.    register int which_menu;        /* which menu indicator */
  31.  
  32. #ifdef DEBUG
  33.    dprintf(b)(stderr,"do button %d (button state id %d)\n",button,button_state);
  34. #endif
  35.  
  36.    /*    Insist on a transition before taking any action.
  37.    */
  38.    if( button == button_state )
  39.       return;
  40.  
  41.    /*    Other button codes, such as chords, are not recognized and have no
  42.     effect.
  43.    */
  44.    switch( button ) {
  45.    case 0:
  46.    case BUTTON_SYS:
  47.    case BUTTON_2:
  48.    case BUTTON_1:
  49.     break;
  50.    default:
  51.     return;
  52.    }
  53.  
  54.    /*    If button was down and now no button is down,
  55.         send the event stating the formerly down button is now up.
  56.     If some button is down, the same or some other,
  57.         do nothing.
  58.     Note that this creates a fundmental property of MGR:  namely that
  59.     once a button is pressed, no other button pressings have any effect
  60.     until all buttons are released.
  61.    */
  62.    if( button_state ) {
  63.       if ( button == 0 ) {
  64.      int    b_event = -button_state;
  65.  
  66.      /* button_state must be cleared before sending a Button_Up event to
  67.         prevent any event action from thinking the button is still down.
  68.      */
  69.          button_state = 0;
  70.          do_event( b_event, active, E_MAIN );
  71.          }
  72.       return;
  73.       }
  74.  
  75.    /* button_state is the global record of the current button state.
  76.    */
  77.    button_state = button;
  78.  
  79.    /* Check for events associated with this button being pushed.
  80.    */
  81.    do_event(button,active,E_MAIN);
  82.    switch (button) {
  83.       case BUTTON_1:    /* temporary vi hack */
  84. #ifdef VI
  85.            if (active && ACTIVE(flags)&W_VI) {
  86.  
  87.               int x = mousex-(ACTIVE(x0)+ACTIVE(text).x);
  88.               int y = mousey-(ACTIVE(y0)+ACTIVE(text).y);
  89.               int dx = ACTIVE(text).wide ? 
  90.                        ACTIVE(text).wide : BIT_WIDE(ACTIVE(window));
  91.               int dy = ACTIVE(text).wide ? 
  92.                        ACTIVE(text).high : BIT_HIGH(ACTIVE(window));
  93.  
  94.               if (x<0 || x > dx)
  95.                  break;
  96.               if (y>=0 && y<=dy) {
  97.                  char buff[10];
  98.                  sprintf(buff,"%dH%d|",
  99.                       y/ACTIVE(font)->head.high+1,
  100.                       x/ACTIVE(font)->head.wide+1);
  101.                  write(ACTIVE(to_fd),buff,strlen(buff));
  102.                  } 
  103.               else if (y<0)
  104.                  write(ACTIVE(to_fd),"\025",1);    /* ASCII Control-U */
  105.               else
  106.                  write(ACTIVE(to_fd),"\004",1);    /* ASCII Control-D */
  107.               }
  108. #endif
  109.            if (active) {
  110.               go_menu(1);
  111.        }
  112.            break;
  113.       case BUTTON_2:                /* for applic. menu */
  114.            if (active) {
  115.               go_menu(0);
  116.        }
  117.            break;
  118.       case BUTTON_SYS:                /* for system operation */
  119.            /* see if mouse is in a window */
  120.            if (mousex < STRIPE)
  121.               win = (WINDOW *) 0;
  122.            else
  123.               for(win=active;win != (WINDOW *) 0;win=W(next))
  124.                  if(mousein(mousex,mousey,win,1))
  125.                     break;
  126.  
  127.            /* do a menu for no window, or active window */
  128.            if (win == active || win == (WINDOW *) 0) {
  129.               if (active && win == active) {
  130.                  state = menu_define(font,active_menu,0,0,
  131.                          PUTCOLOR(W(style)),
  132.                          PUTCOLOR(W(background)));
  133.                  which_menu = 1;
  134.                  }
  135.               else if (next_window >= MAXWIN) {
  136.                  state = menu_define(font,full_menu,0,0,MENU_FG,MENU_BG);
  137.                  which_menu = 2;
  138.                  }
  139.               else {
  140.                  state = menu_define(font,main_menu,0,0,MENU_FG,MENU_BG);
  141.                  which_menu = 3;
  142.                  }
  143.               if (active) {
  144.                  cursor_off();
  145.                  if (which_menu != 1)
  146.                     ACTIVE_OFF();
  147.                  }
  148.               state = menu_setup(state,screen,mousex,mousey,0);
  149.               menu_get(state,mouse,0,0);
  150.               choice = menu_choice(state);
  151.               choice_ok = menu_ischoice(state);
  152.               menu_destroy(state);
  153.               if (choice_ok) {
  154.                  switch(which_menu) {
  155.                     case 1:
  156.              ACTIVE_OFF();
  157.                          (*active_functions[choice])();
  158.                          break;
  159.                     case 2:
  160.                          (*full_functions[choice])();
  161.                          break;
  162.                     case 3:
  163.                          (*main_functions[choice])();
  164.                          break;
  165.                     }
  166.          }
  167.               if (active) {
  168.                  ACTIVE(flags) &= ~W_NOINPUT;
  169.                  ACTIVE_ON();
  170.                  cursor_on();
  171.                  }
  172.           do_button(0);
  173.               }
  174.            else {
  175.            /* bring obscured window to the top */
  176. #ifdef DEBUG
  177.               dprintf(b)(stderr,"activating: %s\r\n",W(tty));
  178. #endif
  179.               if (active) {
  180.                   ACTIVE_OFF();
  181.                   cursor_off();
  182.                   }
  183.               expose(win);
  184.               if (active) {
  185.                  ACTIVE(flags) &= ~W_NOINPUT;
  186.                  ACTIVE_ON();
  187.                  cursor_on();
  188.                  }
  189.               }
  190.            break;
  191.            }
  192.    return;
  193.    }
  194.  
  195. /* hide the active window */
  196.  
  197. int hide_win()
  198.    {
  199.    hide(active);
  200.    }
  201.  
  202. /* quit with confirm */
  203.  
  204. int quit()
  205.    {
  206.    struct menu_state *state;        /* place to keep menu state */
  207.    int confirm;
  208.    
  209.    /* confirm the quit */
  210.  
  211.    state = menu_define(font,quit_menu,0,0,MENU_BG,MENU_FG);
  212.    state = menu_setup(state,screen,mousex,mousey,0);
  213.  
  214.    /* The extra call to menu_get() makes the use of the mouse buttons
  215.       consistent on the menus; namely the action is selected by the button
  216.       going up.
  217.    */
  218.    menu_get(state,mouse,BUTTON_SYS,0);
  219.    menu_get(state,mouse,0,0);
  220.  
  221.    confirm = menu_ischoice(state) ? menu_choice(state) : 0;
  222.    menu_destroy(state);
  223.    if (confirm == M_QUIT) {
  224.       _quit();
  225.       exit(0);
  226.       }
  227.    else if (confirm == M_SUSPEND)
  228.       suspend();
  229.    }
  230.  
  231. /* really quit */
  232.  
  233. int
  234. _quit()
  235.    {
  236.    register WINDOW *win;
  237.    static int really_quit=0;
  238.  
  239.    if (really_quit++) {            /* we're in bad shape */
  240.       perror("PANIC!!  Error during _quit()!");
  241.       setreuid(getuid(),getuid());
  242.       abort();
  243.       }
  244.  
  245.    MOUSE_OFF(mousex,mousey);
  246.  
  247.    sleep(1);        /* let the key (if any) un-press before resetting
  248.             the kbd */
  249.    set_kbd(0);        /* fix up keyboard modes */
  250.    kbd_reset();        /* reset the keyboard */
  251.    reset_tty(0);    /* fix up console tty modes */
  252.  
  253.    /* fix pttys */
  254.    if (geteuid() < 2)
  255.       for(win=active;win != (WINDOW *) 0;win=W(next)) {
  256.             killpg(W(pid),SIGHUP);
  257.          chmod(W(tty),0666);
  258.          chown(W(tty),0,0);
  259.          }
  260.  
  261.    /* fix utmp file */
  262.  
  263. #ifdef WHO
  264.    close(getdtablesize()-1); /* make sure there are enough fd's left */
  265.    for(win=active;win != (WINDOW *) 0;win=W(next))
  266.       if (W(tty))
  267.           rm_utmp(W(tty));
  268.    restore_utmp(0,"");
  269. #endif
  270.  
  271.    CLEAR(screen,BIT_CLR);
  272.    do_cmd( 'q' );    /* do the quiting command */
  273.     bit_destroy(screen);
  274.    }
  275.  
  276. /* redraw the screen, restore contents of saved windows */
  277.  
  278. int redraw()
  279.    {
  280.    register WINDOW *win;
  281.  
  282. #ifdef DEBUG
  283.    dprintf(b)(stderr,"\r\n\tREDRAW\r\n");
  284. #endif
  285.    for(win=active;win != (WINDOW *) 0;win=W(next)) {
  286.       if (W(flags)&W_ACTIVE) {
  287.          save_win(win);
  288.          do_event(EVENT_REDRAW,win,E_MAIN);
  289.          }
  290.       }
  291.  
  292.    erase_win(screen,0,0);
  293.    if (active) {
  294.       for(win=ACTIVE(prev);win != active;win=W(prev)) {
  295.          restore_win(win);
  296.          border(win,BLK_BDR,WH_BDR);
  297.          }
  298.       restore_win(active);
  299.       border(active,BLK_BDR,WH_BDR);
  300.       }
  301.    }
  302.